<!--
 * @Author: Zhouxin 2201_75539691@noreply.gitcode.com
 * @Date: 2024-11-20 20:48:23
 * @LastEditors: Zhouxin 2201_75539691@noreply.gitcode.com
 * @LastEditTime: 2024-11-20 20:51:14
 * @FilePath: \2024.11.20-day08-数组与字符串\demo5.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 查找数组[1,2,3,4,1,2,3,4,2,3,1,1,0]中所有值为1的项的下标 输出为新数组 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr1 = [1, 2, 3, 4, 1, 2, 3, 4, 2, 3, 1, 1, 0];
        var arr2 = [];
        for (var i = 0; i < arr1.length; i++) {
            if (arr1[i] === 1) {
                arr2.push(i);
            }
        }

        console.log(arr2);

    </script>
</body>

</html>